<?php

/**
 * This is the model class for table "m_student_credit_notes".
 *
 * The followings are the available columns in table 'm_student_credit_notes':
 * @property integer $id
 * @property string $cn_date
 * @property integer $invoice_id
 * @property integer $cn_acc_id
 * @property string $ttl_cn
 * @property string $notes
 * @property integer $jurnal_id
 * @property integer $is_active
 * @property string $input_datetime
 * @property integer $user_id
 *
 * The followings are the available model relations:
 * @property MStudentHinvoice $invoice
 * @property MCoa $cnAcc
 * @property MUser $user
 * @property MHjurnal $jurnal
 */
class MStudentCreditNotes extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'm_student_credit_notes';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('cn_date, invoice_id, cn_acc_id, ttl_cn, jurnal_id, input_datetime, user_id', 'required'),
			array('invoice_id, cn_acc_id, jurnal_id, is_active, user_id', 'numerical', 'integerOnly'=>true),
			array('ttl_cn', 'length', 'max'=>14),
			array('notes', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, cn_date, invoice_id, cn_acc_id, ttl_cn, notes, jurnal_id, is_active, input_datetime, user_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'invoice' => array(self::BELONGS_TO, 'MStudentHinvoice', 'invoice_id'),
			'cnAcc' => array(self::BELONGS_TO, 'MCoa', 'cn_acc_id'),
			'user' => array(self::BELONGS_TO, 'MUser', 'user_id'),
			'jurnal' => array(self::BELONGS_TO, 'MHjurnal', 'jurnal_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'cn_date' => 'Cn Date',
			'invoice_id' => 'Invoice',
			'cn_acc_id' => 'Cn Acc',
			'ttl_cn' => 'Ttl Cn',
			'notes' => 'Notes',
			'jurnal_id' => 'Jurnal',
			'is_active' => 'Is Active',
			'input_datetime' => 'Input Datetime',
			'user_id' => 'User',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('cn_date',$this->cn_date,true);
		$criteria->compare('invoice_id',$this->invoice_id);
		$criteria->compare('cn_acc_id',$this->cn_acc_id);
		$criteria->compare('ttl_cn',$this->ttl_cn,true);
		$criteria->compare('notes',$this->notes,true);
		$criteria->compare('jurnal_id',$this->jurnal_id);
		$criteria->compare('is_active',$this->is_active);
		$criteria->compare('input_datetime',$this->input_datetime,true);
		$criteria->compare('user_id',$this->user_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return MStudentCreditNotes the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
